package com.ccrfid.rmc6.appconfig;

import com.ccrfid.rmc6.appconfig.auth.AuthenticationFilter;
import com.ccrfid.rmc6.appconfig.exception.AppExceptionMapper;
import com.ccrfid.rmc6.appconfig.exception.GenericExceptionMapper;
import com.ccrfid.rmc6.appconfig.exception.NotFoundExceptionMapper;
import com.ccrfid.rmc6.appconfig.filter.CORSResponseFilter;
import com.ccrfid.rmc6.appconfig.filter.CustomServerLoggingFilter;
import com.ccrfid.rmc6.appconfig.jackson.JacksonConfig;
import com.ccrfid.rmc6.resource.alarm.AlarmNotifyStrategyResource;
import com.ccrfid.rmc6.resource.alarm.AlarmRecordResource;
import com.ccrfid.rmc6.resource.alarm.AlarmRuleResource;
import com.ccrfid.rmc6.resource.asset.AssetResource;
import com.ccrfid.rmc6.resource.auth.AuthenticationResource;
import com.ccrfid.rmc6.resource.business.chongqing.CQPatrolResource;
import com.ccrfid.rmc6.resource.business.entrance.PersonnelEntranceResource;
import com.ccrfid.rmc6.resource.business.huxi.HuXiResource;
import com.ccrfid.rmc6.resource.business.nightpatrol.NightPatrolResource;
import com.ccrfid.rmc6.resource.business.patrol.PatrolConfigResource;
import com.ccrfid.rmc6.resource.business.patrol.PatrolResource;
import com.ccrfid.rmc6.resource.business.prison.door.DoorResource;
import com.ccrfid.rmc6.resource.business.prison.patrolcheck.PatrolCheckResource;
import com.ccrfid.rmc6.resource.business.prison.rollcall.PrisonRollcallPlaceResource;
import com.ccrfid.rmc6.resource.business.prison.rollcall.PrisonRollcallResource;
import com.ccrfid.rmc6.resource.business.prison.rollcall.SyncHandsetDataResource;
import com.ccrfid.rmc6.resource.business.rollcall.Rollcall2Resource;
import com.ccrfid.rmc6.resource.business.rollcall.RollcallResource;
import com.ccrfid.rmc6.resource.business.visitroom.VisitRoomResource;
import com.ccrfid.rmc6.resource.dbg.*;
import com.ccrfid.rmc6.resource.device.*;
import com.ccrfid.rmc6.resource.export.DataExportResource;
import com.ccrfid.rmc6.resource.map.MapResource;
import com.ccrfid.rmc6.resource.mattress.BedResource;
import com.ccrfid.rmc6.resource.open.OpenResource;
import com.ccrfid.rmc6.resource.open.OpenV2Resource;
import com.ccrfid.rmc6.resource.personnel.PersonnelResource;
import com.ccrfid.rmc6.resource.personnel.PersonnelVitalSignResource;
import com.ccrfid.rmc6.resource.personnel.SyncPrisonerResource;
import com.ccrfid.rmc6.resource.poi.PoiLabelResource;
import com.ccrfid.rmc6.resource.poi.PoiLineResource;
import com.ccrfid.rmc6.resource.poi.PoiLocationResource;
import com.ccrfid.rmc6.resource.sse.SseResource;
import com.ccrfid.rmc6.resource.sys.*;
import com.ccrfid.rmc6.resource.toolcase.ToolCaseResource;
import com.ccrfid.rmc6.resource.vehicle.VehicleResource;
import com.ccrfid.rmc6.resource.video.VideoCameraResource;
import com.ccrfid.rmc6.resource.video.VideoOrgResource;
import com.ccrfid.rmc6.resource.video.VideoPlatformResource;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.media.sse.SseFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.stereotype.Component;

@Component
public class JerseyConfig extends ResourceConfig {
    public JerseyConfig() {
        //Jackson
        register(JacksonConfig.class);
        register(JacksonFeature.class);
        //
        register(MultiPartFeature.class);
        register(SseFeature.class);
        //注册资源类
        registerEndpoints();
        //注册异常捕获mapper
        registerExceptionHandlers();
        //CORS
        register(CORSResponseFilter.class);
        //Logging
        register(CustomServerLoggingFilter.class);
        //authentication filter
        register(AuthenticationFilter.class);
    }

    //packages("com.ccrfid.rmc6.resource");
    //使用这种方式会造成java -jar运行失败
    private void registerEndpoints() {
        //alarm
        register(AlarmNotifyStrategyResource.class);
        register(AlarmRecordResource.class);
        register(AlarmRuleResource.class);

        //asset
        register(AssetResource.class);

        //auth
        register(AuthenticationResource.class);

        //business
        register(PersonnelEntranceResource.class);
        register(PatrolConfigResource.class);
        register(PatrolResource.class);

        register(DoorResource.class);
        register(PatrolCheckResource.class);

        register(PrisonRollcallPlaceResource.class);
        register(PrisonRollcallResource.class);
        register(SyncHandsetDataResource.class);
        register(RollcallResource.class);
        register(Rollcall2Resource.class);
        register(VisitRoomResource.class);
        register(NightPatrolResource.class);

        register(CQPatrolResource.class);
        register(HuXiResource.class);

        //debug
        register(LocationManagerDebugResource.class);
        register(TestResource.class);
        register(WebClientDebugResource.class);
        register(WebServerResource.class);

        //device
        register(AlerterResource.class);
        register(CardreaderResource.class);
        register(CardResource.class);
        register(LocatorResource.class);
        register(NetreaderResource.class);

        //map
        register(MapResource.class);

        //mattress
        register(BedResource.class);

        //open
        register(OpenResource.class);
        register(OpenV2Resource.class);

        //personnel
        register(PersonnelResource.class);
        register(PersonnelVitalSignResource.class);
        register(SyncPrisonerResource.class);

        //poi
        register(PoiLabelResource.class);
        register(PoiLineResource.class);
        register(PoiLocationResource.class);

        //sse
        register(SseResource.class);

        //sys
        register(AccountResource.class);
        register(AppModuleResource.class);
        register(DictResource.class);
        register(KeyValueResource.class);
        register(OrgResource.class);
        register(RoleResource.class);
        register(RoomResource.class);
        register(UploadFileResource.class);

        //toolcase
        register(ToolCaseResource.class);

        //vehicle
        register(VehicleResource.class);

        //video
        register(VideoCameraResource.class);
        register(VideoOrgResource.class);
        register(VideoPlatformResource.class);

        //export
        register(DataExportResource.class);

    }

    private void registerExceptionHandlers() {
        register(GenericExceptionMapper.class);
        register(NotFoundExceptionMapper.class);
        register(AppExceptionMapper.class);
    }
}
